package org.tarena.dang.action.order;

import java.sql.SQLException;
import java.util.List;

import org.tarena.dang.action.BaseAction;
import org.tarena.dang.entity.User;
import org.tarena.dang.entity.UserAdress;
import org.tarena.dang.service.OrderService;
import org.tarena.dang.service.OrderServiceImp;
import org.tarena.dang.util.Constant;

public class GetAddressAction extends BaseAction {
	private String add;
	private UserAdress userAdd;
	private int addId;
	List<UserAdress> listAdd;
	public String execute(){
		System.out.println("get address о┤лл┴╦");
		User user = (User)session.get(Constant.USER);
		if(user==null){
			return "login";
		}
		//List<UserAdress> listAdd = new ArrayList<UserAdress>();
		OrderService orderService = new OrderServiceImp();
		
//		StringBuilder d = new StringBuilder();
		try {
				listAdd = orderService.getAddress(user.getId());
//				for(UserAdress address:listAdd){
//					if(address.getId()==addId){
//						//uAdd = address;
//						System.out.println(address.getFullAddress());
//						System.out.println("id====="+user.getId());
//						d.append(address.getReceiveName());
//						d.append("/");
//						d.append(address.getFullAddress());
//						d.append("/");
//						d.append(address.getPostalCode());
//						d.append("/");
//						d.append(address.getPhone());
//						d.append("/");
//						d.append(address.getMobile());
//						add = d.toString();
//						break;
//					}
//				}
				if(addId!=0){
					userAdd = orderService.getAddById(addId);
					System.out.println("*************"+userAdd.getFullAddress());
				}
			
			
			
			//System.out.println(add.toString());
//			JSONArray arr = new JSONArray();
//			add = JSONArray.fromObject(address);
//			System.out.println("arr====="+add.toString());
//			add = arr;
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		System.out.println("get address о┤лл          ok");
		return "success";
	}
	public String getAdd() {
		return add;
	}
	public void setAdd(String add) {
		this.add = add;
	}
	public List<UserAdress> getListAdd() {
		return listAdd;
	}
	public void setListAdd(List<UserAdress> listAdd) {
		this.listAdd = listAdd;
	}
	public int getAddId() {
		return addId;
	}
	public void setAddId(int addId) {
		this.addId = addId;
	}
	public UserAdress getUserAdd() {
		return userAdd;
	}
	public void setUserAdd(UserAdress userAdd) {
		this.userAdd = userAdd;
	}
	
	
}
